const { global_data } = require("../dao/mysql");

function queryMysql(queryStr){
  let pool=global_data.connPool
  return new Promise((resolve,reject)=>{

      pool.getConnection((err,conn)=>{
          if(err){
              reject(err)
          }else {
              conn.query(queryStr,(err, results, fields)=> {
                  if(err){
                      reject(err)
                  }else{
                      resolve({results,fields})
                  }
              });
          }
          try {
              pool.releaseConnection(conn)
          }catch(err){
              reject(err)
              console.log('释放连接池连接出错 --> ',err)
          }

      })
  })
}

module.exports={
  queryMysql
}
